package com.example.badmintonWeb.controller;

import com.example.badmintonCommon.entity.Gym;
import com.example.badmintonCommon.entity.Notice;
import com.example.badmintonCommon.entity.Order;
import com.example.badmintonCommon.entity.User;
import com.example.badmintonCommon.pojo.Result;
import com.example.badmintonCommon.util.ThreadLocalUtil;
import com.example.badmintonUser.admin.AdminServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {
    private final AdminServer adminServer;

    @Autowired
    public AdminController(AdminServer adminServer){
        this.adminServer=adminServer;
    }

    //添加场地
    @PostMapping("/addGym")
    public Result<String> AddGym(@RequestParam Integer gymprise){
        Result result=adminServer.AddGym(gymprise);
        return result;
    }

    //删除场地
    @PostMapping("/DeleteGymById")
    public Result<String> DeleteGymById(@RequestParam Integer id){
        Result result=adminServer.DeleteGymById(id);
        return result;
    }

    //获得所有用户信息
    @GetMapping("/GetUsersList")
    public Result<List<User>> GetUsersList(){
        Result result=adminServer.GetUsersList();
        return result;
    }

    // 发布公告
    @PostMapping("/addNotice")
    public Result<String> addNotice(@RequestBody Notice notice) {
        adminServer.AddNotice(notice);
        return Result.success("公告发布成功");
    }

    // 修改公告
    @PutMapping("/updateNotice")
    public Result<String> updateNotice(@RequestBody Notice notice) {
        adminServer.UpdateNotice(notice);
        return Result.success("公告修改成功");
    }

    // 查询所有公告
    @GetMapping("/notices")
    public Result<List<Notice>> getAllNotices() {
        return Result.success(adminServer.FindAllNotices());
    }

    // 按 ID 查询公告
    @GetMapping("/notice/{id}")
    public Result<Notice> getNoticeById(@PathVariable Integer id) {
        return Result.success(adminServer.FindNoticeById(id));
    }

    @GetMapping("/getOrders")
    public Result<List<Order>> getOrders(){
        Result result=adminServer.getOrders();
        return result;
    }

    @GetMapping("/getGyms")
    public Result<List<Gym>> getGyms(){
        Result result=adminServer.getGyms();
        return result;
    }

    //用户通过手机号登录
    @PostMapping("/login")
    public Result<String> AdminLogin(@RequestParam String tel,@RequestParam String psw){
        Result result=adminServer.AdminLogin(tel,psw);
        return result;
    }

    @PostMapping("/chanagePlacePrice")
    public Result<String> changePlacePrice(@RequestParam Integer id,@RequestParam Integer price){
        Result result=adminServer.changePlacePrice(id,price);
        return result;
    }

    @PostMapping("/lockOrUnlockUser")
    public Result<String> lockOrUnlockUser(@RequestParam String tel){
        Result result=adminServer.lockOrUnlockUser(tel);
        return result;
    }

    @PostMapping("/deleteNotice")
    public Result<String> deleteNotice(@RequestParam int id){
        System.out.println("到后端");
        Result result=adminServer.deleteNotice(id);
        return result;
    }



}
